package com.jlb.demo.payment;

/**
 * 支付宝支付实现类 - 演示多态
 */
public class AlipayPayment implements Payment {
    
    @Override
    public boolean pay(Long orderId, Double amount) {
        // 模拟调用支付宝支付API
        System.out.println("=== 支付宝支付处理 ===");
        System.out.println("订单ID: " + orderId);
        System.out.println("支付金额: " + amount + " 元");
        System.out.println("手续费: " + calculateFee(amount) + " 元");
        System.out.println("实际到账: " + (amount - calculateFee(amount)) + " 元");
        
        // 模拟支付处理时间
        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        
        // 模拟支付成功（95%成功率）
        boolean success = Math.random() > 0.05;
        if (success) {
            System.out.println("✅ 支付宝支付成功！");
        } else {
            System.out.println("❌ 支付宝支付失败：余额不足");
        }
        
        return success;
    }
    
    @Override
    public String getPaymentMethod() {
        return "支付宝支付";
    }
    
    @Override
    public Double getFeeRate() {
        return 0.5; // 0.5%手续费
    }
} 